<?php $auth=0; ?>
<?php include 'lib/includes.php'; ?>
<?php include 'partials/header_menu.php';?> 
<meta  http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<?php 
$select=$db->query('select prescriptionId,clientNom,clientPrenom,clientPhone,medicamentNom,medicamentPrix,prescriptionDate,mpDetails,vendeurNom,vendeurPrenom from prescription inner join medicament on medicament.medicamentId=prescription.medicamentId inner join vendeur on prescription.vendeurId=vendeur.vendeurId inner join client on client.clientId=prescription.clientId inner join methodepayement on prescription.methodepayement=methodepayement.methodepayement');
$prescriptions=$select->fetchAll();
/**
*suppression
**/
if(isset($_GET['delete']))
{
	$id=$db->quote($_GET['delete']);
	$db->query("delete from prescription where prescriptionId=$id");
}
?>

<br>
<br>
<h3>&nbsp;La liste des préscriptions</h3>
<br>
<p>&nbsp;&nbsp;<a href="prescription_edit.php" class="btn btn-success">ajouter une nouvelle prescription <span  class="glyphicon glyphicon-plus"></span></a><p>
<center>
<div id="pres" style="width: 100%; height: 380px;"></div>
	<script>var i=0;</script>
	<?php  foreach($prescriptions as $prescription){ 
	//echo json_encode($soc); 
	?>
	<script>
	var sup='<a href="prescription_edit.php?id=<?php echo($prescription['prescriptionId']); ?>" class="glyphicon glyphicon-edit">&nbsp;editer</a>&nbsp;&nbsp;<a href="drug.php?delete=<?php echo($prescription['prescriptionId']); ?>" class="glyphicon glyphicon-remove" onclick="">&nbsp;supprimer</a>&nbsp;&nbsp;<a href="pdf_server.php?id=<?php echo $prescription['prescriptionId']?>&amp;n=<?php echo $prescription['clientNom']?>&amp;pr=<?php echo $prescription['clientPrenom']?>&amp;cp=<?php echo $prescription['clientPhone']?>&amp;mn=<?php echo $prescription['medicamentNom']?>&amp;mp=<?php echo $prescription['medicamentPrix']?>&amp;dv=<?php echo $prescription['prescriptionDate']?>&amp;mpd=<?php echo $prescription['mpDetails']?>&amp;vn=<?php echo $prescription['vendeurNom']?>&amp;vp=<?php echo $prescription['vendeurPrenom']?>"class="glyphicon glyphicon-print" name="imprimer">&nbsp;imprimer</a>';
	i++;
	$('#pres').w2grid({
    name: 'grid',
    header: 'Liste des prescriptions',
    show: {
        toolbar: true,
        footer: true
    },
    columns: [
        { field: 'recid', caption: 'Num', size: '5%', sortable: true, attr: 'align=center' },
		{ field: 'ID', caption: 'ID du prescription', size: '10%', sortable: true, resizable: true },
        { field: 'nom', caption: 'Nom du client', size: '10%', sortable: true, resizable: true },
		{ field: 'prenom', caption: 'Prénom du client', size: '10%', sortable: true, resizable: true },
        { field: 'portable', caption: 'Téléphone', size: '10%', resizable: true },
        { field: 'med', caption: 'Nom du médicament', size: '10%', resizable: true },
		{ field: 'prix', caption: 'Prix', size: '10%', resizable: true },
		{ field: 'date', caption: 'Date', size: '10%', resizable: true },
		{ field: 'mp', caption: 'Méthode de payement', size: '10%', resizable: true },
		{ field: 'nomV', caption: 'Nom du vendeur ', size: '10%', resizable: true },
		{ field: 'prenomV', caption: 'Prénom du vendeur', size: '10%', resizable: true },
		{ field: 'link', caption: 'Action', size: '20%', resizable: true },
		
    ],
    searches: [
		{ field: 'ID', caption: 'ID du prescription', type: 'text' },
        { field: 'nom', caption: 'Nom du client', type: 'text' },
        { field: 'prenom', caption: 'Prénom du client', type: 'text' },
        { field: 'portable', caption: 'Téléphone', type: 'text' },
		{ field: 'med', caption: 'Nom du médicament', type: 'text' },
		{ field: 'prix', caption: 'Prix', type: 'text' },
		{ field: 'date', caption: 'Date', type: 'text' },
		{ field: 'mp', caption: 'Méthode de payement', type: 'text' },
		{ field: 'nomV', caption: 'Nom du vendeur', type: 'text' },
		{ field: 'prenomV', caption: 'Prénom du vendeur', type: 'text' },
    ],
    sortData: [{ field: 'recid', direction: 'ASC' }]
    });
	w2ui['grid'].add({ recid:  i,
	ID: <?php echo($prescription['prescriptionId']); ?> ,
	nom: '<?php echo($prescription['clientNom']); ?>' ,
	prenom: '<?php echo($prescription['clientPrenom']); ?>', 
	portable: '<?php echo($prescription['clientPhone']); ?>',
	med: '<?php echo($prescription['medicamentNom']); ?>',
	prix: '<?php echo($prescription['medicamentPrix']); ?>',
	date: '<?php echo($prescription['prescriptionDate']); ?>',
	mp: '<?php echo($prescription['mpDetails']); ?>',
	nomV: '<?php echo($prescription['vendeurNom']); ?>',
	prenomV: '<?php echo($prescription['vendeurPrenom']); ?>',
	link:sup });
	</script>
	<?php }?>	
</center>
<br>
<?php include 'partials/footer.php';?>


